package laos.src;

import laos.src.R;
import android.app.Activity;
import android.content.Intent;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

public class Play extends Activity implements OnClickListener {

	protected static EditText ip, port;
	protected static TextView join, create;
	//protected static Play t;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
				WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		setContentView(R.layout.play);
		//t = this;
		getViews();
		setFonts();
		join.setOnClickListener(this);
		create.setOnClickListener(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
		Music.play(this, R.raw.game);
	}

	@Override
	protected void onPause() {
		super.onPause();
		Music.stop(this);
	}

	private void getViews() {
		ip = (EditText) findViewById(R.id.editIP);
		port = (EditText) findViewById(R.id.editPort);
		// password = (EditText) findViewById(R.id.editPassword);
		join = (TextView) findViewById(R.id.btJoin);
		create = (TextView) findViewById(R.id.btCreate);
	}

	private void setFonts() {
		((TextView) findViewById(R.id.txtIP)).setTypeface(MainMenu.tf2);
		((TextView) findViewById(R.id.txtPort)).setTypeface(MainMenu.tf2);
		// ((TextView) findViewById(R.id.txtPassword)).setTypeface(MainMenu.tf);
		join.setTypeface(MainMenu.tf);
		create.setTypeface(MainMenu.tf);
	}

	@Override
	public void onClick(View v) {
		Intent i = null;
		switch (v.getId()) {
		case R.id.btCreate:
			i = new Intent(this, AreaSelectorActivity.class);
			i.putExtra("IP", ip.getText().toString());
			i.putExtra("PORT", port.getText().toString());
			startActivity(i);
			break;
		case R.id.btJoin:
			i = new Intent(this, GameActivity.class);
			i.putExtra("IP", ip.getText().toString());
			i.putExtra("PORT", port.getText().toString());
			i.putExtra("IS_GAME_OWNER", false);
			startActivity(i);
			break;
		}
	}

}
